#!/usr/bin/env perl

# Perl parameter example with Getopt::Long, with optional param.
# License: CC0

# Usage:
# ./param2.pl 'some test text'
# ./param2.pl -p 'append test' 'some test'

# To handle CLI parameters
use Getopt::Long;

# Shows up when --help or -h is passed
sub help_text {
	print("usage: param1.pl [-h] [TEXT]

Prints the text that is passed to it.

optional arguments:
  -h, --help            show this help message and exit
  -p APPEND_TEXT, --append APPEND_TEXT
                        append some text with print (optional)\n");
	exit;
}

my $append;

# An example subroutine that just prints whatever is passed to it.
sub printit {
	print(shift . "\n");
	print("$append\n") if ($append);
}

# Process CLI parameters and update config values as necessary
GetOptions ('<>'             => \&printit,
			"p|append=s"     => \$append,
			"h|help"         => \&help_text)
or die("Error in command line arguments. Please review and try again.\n");
